package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-09-25
 * Description
 */
public class Sogou2 {


    public String rotatePassword (String[] s1, String[] s2) {
        // write code here
        
        int n = s1.length;
        char[][] top = new char[n][];
        char[][] bottom = new char[n][];
        for (int i = 0; i < n; i++) {
            char[] arrayTop = s1[i].toCharArray();
            char[] arrayBottom = s2[i].toCharArray();
            top[i] = arrayTop;
            bottom[i] = arrayBottom;
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int k = 0; k < n-1; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (top[i][j] == '0') {
                        stringBuilder.append(bottom[i][j]);
                    }
                }
            }
            reverse(top);
        }

        return stringBuilder.toString();
    }

    public void reverse(char[][] matrix) {
        int n = matrix.length;
        char[][] temp = new char[n][n];
        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                temp[row][col] = matrix[n - 1- col][row];
            }
        }

        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                matrix[row][col] = temp[row][col];
            }
        }
    }


}
